home *** CD-ROM | disk | FTP | other *** search
/ Holt Researcher: American History / Holt Researcher: American History.iso / pc / modules / dbtable.dxr / 00015_Text & List Code.ls < prev    next >
Encoding:
Text File  |  2000-01-18  |  6.6 KB  |  293 lines

  1. global gDBTableVarList
  2.  
  3. on EvalKeyPressed
  4.   if IsKeyBoardEquivalentDown() then
  5.     MyObj = getaProp(gDBTableVarList, GetObjProp())
  6.     case the key of
  7.       "c":
  8.         TableCopy(MyObj)
  9.       "p":
  10.         print(MyObj)
  11.       "s":
  12.         save(MyObj)
  13.     end case
  14.   end if
  15. end
  16.  
  17. on DeleteFirstItem xList
  18.   DupList = duplicate(xList)
  19.   deleteAt(DupList, 1)
  20.   return DupList
  21. end
  22.  
  23. on SearchList xList, target
  24.   ListCount = count(xList)
  25.   repeat with rc1 = 1 to ListCount
  26.     xItem = getAt(xList, rc1)
  27.     if listp(xItem) then
  28.       repeat with rc2 in xItem
  29.         if xItem = target then
  30.           FoundIndex = rc1
  31.         end if
  32.       end repeat
  33.       next repeat
  34.     end if
  35.     if xItem = target then
  36.       FoundIndex = rc1
  37.     end if
  38.   end repeat
  39.   return FoundIndex
  40. end
  41.  
  42. on MakePlatformFileName xText
  43.   xText = RemoveReturns(xText)
  44.   xText = RemovePathDelimiters(xText)
  45.   if the machineType = 256 then
  46.     if xText contains "." then
  47.       Pos = offset(".", xText)
  48.       xText = char 1 to Pos - 1 of xText
  49.     end if
  50.     legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
  51.     MaxCount = length(xText)
  52.     repeat with rc = 1 to MaxCount
  53.       if not (legalChars contains char rc of xText) then
  54.         put " " into char rc of xText
  55.       end if
  56.     end repeat
  57.     repeat while xText contains " "
  58.       CharNum = offset(" ", xText)
  59.       if CharNum > 0 then
  60.         delete char CharNum of xText
  61.       end if
  62.     end repeat
  63.     return char 1 to 8 of xText
  64.   else
  65.     return xText
  66.   end if
  67. end
  68.  
  69. on MakeNumericOnly xText
  70.   legalChars = "1234567890"
  71.   MaxCount = length(xText)
  72.   repeat with rc = 1 to MaxCount
  73.     if not (legalChars contains char rc of xText) then
  74.       put " " into char rc of xText
  75.     end if
  76.   end repeat
  77.   repeat while xText contains " "
  78.     CharNum = offset(" ", xText)
  79.     if CharNum > 0 then
  80.       delete char CharNum of xText
  81.     end if
  82.   end repeat
  83.   return xText
  84. end
  85.  
  86. on GetOnStageRects TableRectList
  87.   OnStageList = []
  88.   StageRect = rect(0, 0, the stageRight - the stageLeft, the stageBottom - the stageTop)
  89.   repeat with xRect in TableRectList
  90.     if inside(point(xRect.left, xRect.top), StageRect) and inside(point(xRect.right, xRect.bottom), StageRect) then
  91.       append(OnStageList, xRect)
  92.     end if
  93.   end repeat
  94.   return OnStageList
  95. end
  96.  
  97. on GetRectWidth xRect
  98.   return getAt(xRect, 1) - getAt(xRect, 3)
  99. end
  100.  
  101. on GetRectHeight xRect
  102.   return getAt(xRect, 4) - getAt(xRect, 2)
  103. end
  104.  
  105. on RemoveBlankLines xText
  106.   ReturnString = xText
  107.   LineMax = the number of lines in ReturnString
  108.   repeat with rc = LineMax down to 1
  109.     LineText = line rc of ReturnString
  110.     if (LineText = EMPTY) or (LineText = " ") then
  111.       delete line rc of ReturnString
  112.       LineMax = the number of lines in ReturnString
  113.     end if
  114.   end repeat
  115.   return ReturnString
  116. end
  117.  
  118. on ReplaceCaretwithReturn xText
  119.   repeat while xText contains "^"
  120.     Pos = offset("^", xText)
  121.     put RETURN into char Pos of xText
  122.   end repeat
  123.   return xText
  124. end
  125.  
  126. on FindandReplace xText, FindText, ReplaceText
  127.   if ReplaceText = EMPTY then
  128.     alert("FindandReplace: ReplaceText cannot be Empty String")
  129.   end if
  130.   MaxCount = length(xText)
  131.   repeat with rc = 1 to MaxCount
  132.     if charToNum(FindText) = charToNum(char rc of xText) then
  133.       put ReplaceText into char rc of xText
  134.     end if
  135.   end repeat
  136.   return xText
  137. end
  138.  
  139. on RemoveString xText, FindText
  140.   MaxCount = length(xText)
  141.   repeat while xText contains FindText
  142.     Pos = offset(FindText, xText)
  143.     delete char Pos of xText
  144.   end repeat
  145.   return xText
  146. end
  147.  
  148. on CountNBSpace xText
  149.   count = 0
  150.   WindowsNBS = numToChar(160)
  151.   MacNBS = numToChar(202)
  152.   repeat while xText contains WindowsNBS
  153.     Pos = offset(WindowsNBS, xText)
  154.     count = count + 1
  155.     delete char Pos of xText
  156.   end repeat
  157.   repeat while xText contains MacNBS
  158.     Pos = offset(MacNBS, xText)
  159.     count = count + 1
  160.     delete char Pos of xText
  161.   end repeat
  162.   return count
  163. end
  164.  
  165. on AppendNbs xText, MaxCount
  166.   if the machineType = 256 then
  167.     nbs = numToChar(160)
  168.   else
  169.     nbs = numToChar(202)
  170.   end if
  171.   repeat with rc = 1 to MaxCount
  172.     xText = xText & nbs
  173.   end repeat
  174.   return xText
  175. end
  176.  
  177. on RectToLoc xRect
  178.   l = getAt(xRect, 1)
  179.   t = getAt(xRect, 2)
  180.   R = getAt(xRect, 3)
  181.   b = getAt(xRect, 4)
  182.   xCenter = (R - l) / 2
  183.   if ((l mod 2) = 1) and ((R mod 2) = 1) then
  184.     xCenter = xCenter - 1
  185.   end if
  186.   yCenter = (b - t) / 2
  187.   xPoint = point(l + xCenter, t + yCenter)
  188.   return xPoint
  189. end
  190.  
  191. on IsRectVisible xRect
  192.   l = getAt(xRect, 1)
  193.   t = getAt(xRect, 2)
  194.   R = getAt(xRect, 3)
  195.   b = getAt(xRect, 4)
  196.   return inside(point(l, t), (the stage).rect) and inside(point(R, b), (the stage).rect)
  197. end
  198.  
  199. on CreateLookUpList paramList
  200.   list = []
  201.   repeat with rc in paramList
  202.     append(list, getPos(paramList, rc))
  203.   end repeat
  204.   return list
  205. end
  206.  
  207. on LineItemCount xText
  208.   storeDelimiter = the itemDelimiter
  209.   the itemDelimiter = TAB
  210.   xNumber = the number of items in xText
  211.   the itemDelimiter = storeDelimiter
  212.   return xNumber
  213. end
  214.  
  215. on BlankLine xText
  216.   return (xText = EMPTY) or (xText = " ")
  217. end
  218.  
  219. on RemoveSpaces xText
  220.   ReturnString = xText
  221.   repeat while ReturnString contains " "
  222.     SpaceLoc = offset(" ", ReturnString)
  223.     delete char SpaceLoc of ReturnString
  224.   end repeat
  225.   return ReturnString
  226. end
  227.  
  228. on RemovePathDelimiters xText
  229.   if the machineType = 256 then
  230.     delimiter = "\"
  231.   else
  232.     delimiter = ":"
  233.   end if
  234.   repeat while xText contains delimiter
  235.     CharNum = offset(delimiter, xText)
  236.     if CharNum > 0 then
  237.       delete char CharNum of xText
  238.     end if
  239.   end repeat
  240.   return xText
  241. end
  242.  
  243. on RemoveBorderSpaces xText
  244.   ReturnString = xText
  245.   repeat while char 1 of ReturnString = " "
  246.     delete char 1 of ReturnString
  247.   end repeat
  248.   repeat while char length(ReturnString) of ReturnString = " "
  249.     delete char length(ReturnString) of ReturnString
  250.   end repeat
  251.   return ReturnString
  252. end
  253.  
  254. on InSelection SpriteRect, selRect
  255.   SpriteL = getAt(SpriteRect, 1) + 2
  256.   SpriteT = getAt(SpriteRect, 2) + 2
  257.   SpriteR = getAt(SpriteRect, 3) - 2
  258.   SpriteB = getAt(SpriteRect, 4) - 2
  259.   if inside(point(SpriteL, SpriteT), selRect) then
  260.     return 1
  261.   end if
  262.   if inside(point(SpriteL, SpriteB), selRect) then
  263.     return 1
  264.   end if
  265.   if inside(point(SpriteR, SpriteT), selRect) then
  266.     return 1
  267.   end if
  268.   if inside(point(SpriteR, SpriteB), selRect) then
  269.     return 1
  270.   end if
  271.   return 0
  272. end
  273.  
  274. on EvalRectUnion SpriteRect, selRect
  275.   SpriteL = getAt(SpriteRect, 1) + 2
  276.   SpriteT = getAt(SpriteRect, 2) + 2
  277.   SpriteR = getAt(SpriteRect, 3) - 2
  278.   SpriteB = getAt(SpriteRect, 4) - 2
  279.   if inside(point(SpriteL, SpriteT), selRect) then
  280.     return 1
  281.   end if
  282.   if inside(point(SpriteL, SpriteB), selRect) then
  283.     return 1
  284.   end if
  285.   if inside(point(SpriteR, SpriteT), selRect) then
  286.     return 1
  287.   end if
  288.   if inside(point(SpriteR, SpriteB), selRect) then
  289.     return 1
  290.   end if
  291.   return 0
  292. end
  293.